#include "anry-stock-library-config.h"
#include "DataRetrieve.h"

// global vars
static DataRetrieve* g_p_data_retrieve = NULL;
static bool is_library_already_init = false;

int ANRY_STOCK_LIBRARY::InitLibrary()
{
	DEBUG_OUTPUT_WITH_FUNCTION_NAME( DEBUG_LEVEL_DEBUG, "" );

	if( !is_library_already_init )
	{
		// create data retrieve
		g_p_data_retrieve = new DataRetrieve( "mops.db" );
		
		// set flag to true
		is_library_already_init = true;
	}
	
	return 0;
}

int ANRY_STOCK_LIBRARY::ReleaseLibrary()
{
	DEBUG_OUTPUT_WITH_FUNCTION_NAME( DEBUG_LEVEL_DEBUG, "" );
	
	// free data retrieve
	if( g_p_data_retrieve )
	{
		delete g_p_data_retrieve;
		g_p_data_retrieve = NULL;
	}
	
	// reset flag
	is_library_already_init = false;
}

void* ANRY_STOCK_LIBRARY::GetDataRetrieve()
{
	DEBUG_OUTPUT_WITH_FUNCTION_NAME( DEBUG_LEVEL_DEBUG, "" );
	
	return g_p_data_retrieve;
}
